// pages/search/search.js
const db = wx.cloud.database()
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    movieList: [] // 保存符合条件的电影数据
  },
  onSearch: function (event) {
      db.collection('movies').get().then(res => {
        var movies = []
        for (let idx in res.data) {
          var movieObj = {
            id: res.data[idx]._id,
            title: res.data[idx].title,
            poster: res.data[idx].poster,
            bofang:res.data[idx].bofang,
            translation:res.data[idx].translation,
            type:res.data[idx].type,
            people:res.data[idx].people,
            time:res.data[idx].time,
          }
          movies.push(movieObj)
        }
        this.setData({movies: movies})
        const keyword = event.detail.value
    const movieList = movies.filter(movies => {
      return movies.title.includes(keyword)
    })
    this.setData({
      movieList: movieList
    })
      })
  },
  onXiangqing:function(event){
    const id = event.currentTarget.dataset.id;
    console.log(id)
    wx.navigateTo({
      url: `/pages/xiangqing/xiangqing?id=${id}`
    })
  },
  onMovieTap: function (event) {
    const id = event.currentTarget.dataset.id;
    console.log(id)
    wx.navigateTo({
      url: `/pages/cinema/cinema?id=${id}`
    })
  },
})
